package yancy.modules.sys.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import yancy.common.utils.MapUtils;
import yancy.modules.sys.dao.SysBookFileDao;
import yancy.modules.sys.entity.SysBookFile;
import yancy.modules.sys.service.SysBookFileService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author dongyang
 * @since 2021-07-27 17:41
 */
@Service
public class SysBookFileServiceImpl
    extends ServiceImpl<SysBookFileDao, SysBookFile>
    implements SysBookFileService {
    @Override
    public void saveOrUpdate(Long bookId, List<Long> fileIdList) {
        if(CollectionUtils.isEmpty(fileIdList)){
            return ;
        }

        this.removeByMap(new MapUtils().put("book_id", bookId));


        //保存用户与角色关系
        for(Long fileId : fileIdList){
            SysBookFile bookFile = new SysBookFile();
            bookFile.setBookId(bookId);
            bookFile.setFileId(fileId);

            this.save(bookFile);
        }
    }

    @Override
    public List<Long> queryFileIdList(Long bookId) {
        return baseMapper.queryFileIdList(bookId);
    }
}
